﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using YaAppoint.Appointments;
using YaAppoint.Appointments.AutoAppoint;

namespace YaAppoint.Web.Controllers
{
    public class AutoAppointController(IAutoAppointAppService autoAppointAppService,
                                       IAppointmentAppService appointmentAppService) : AbpController
    {
        private readonly IAutoAppointAppService _autoAppointAppService = autoAppointAppService;
        private readonly IAppointmentAppService _appointmentAppService = appointmentAppService;

        //select Name, count(Name) 数量 from[dbo].[pacs_view_exam_apply_item]
        //group by  Name
        //order by 数量 Desc


        /// <summary>
        /// 自动预约
        /// </summary>
        [AllowAnonymous]
        [HttpGet("/api/auto-appoint/appoint")]
        public async Task<IActionResult> AutoAppoint(string applyNumbers, string needPage)
        {
            bool need = false;
            if (needPage.Equals("true"))
            {
                need = true;
            }
            var data = await _autoAppointAppService.Appoint(applyNumbers, need);
            return new JsonResult(data);
        }

        /// <summary>
        /// 获取打印信息
        /// </summary>
        /// <param name="applyNumber">申请单号，英文逗号隔开</param>
        /// <returns></returns>
        [HttpGet("/api/auto-appoint/getPrintData")]
        public async Task<IActionResult> GetPrintData(string applyNumbers)
        {
            return new JsonResult(await _appointmentAppService.GetPrintData(applyNumbers));
        }
    }
}
